<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class Manufacturer extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'manufacturer';

    public function scopeSearch($query, $params)
    {
        if(!empty($params['manufacturer_name'])){
            $query->where('manufacturer_name', 'like','%'.$params['manufacturer_name'].'%');
        }
        if(!empty($params['manufacturer_address'])){
            $query->where('manufacturer_address', 'like','%'.$params['manufacturer_address'].'%');
        }
        if(!empty($params['manufacturer_phone'])){
            $query->where('manufacturer_phone', 'like','%'.$params['manufacturer_phone'].'%');
        }
        return $query;
    }

    public function goods()
    {
        return $this->hasMany(Goods::class);
    }

    //进货记录
    public function restock()
    {
        return $this->hasMany(Restock::class);
    }

}
